/*
 * File Name：PayStatusActivity.java
 * Copyright：Copyright 2008-2014 CiWong.Inc. All Rights Reserved.
 * Description： PayStatusActivity.java
 * Modify By：bin
 * Modify Date：2014年4月8日
 * Modify Type：Add
 */
package com.ciwong.mobilepay.ui;

import android.app.LocalActivityManager;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.content.res.ResourcesCompat;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.ciwong.libs.utils.CWLog;
import com.ciwong.mobilelib.R;
import com.ciwong.mobilelib.i.ViewOnClickListener;
import com.ciwong.mobilelib.ui.BaseActivity;
import com.ciwong.mobilelib.widget.TitleBar;
import com.ciwong.mobilepay.bean.PayDetail;
import com.ciwong.mobilepay.i.GoBackListener;
import com.ciwong.mobilepay.view.PayResult;
import com.ciwong.mobilepay.view.PayStatus;

/**
 * 支付状态ActivityGroup
 * 
 * @author bin
 * @version ciwong v.1.0 2014年4月8日
 * @since ciwong v.1.0
 */
public class PayStatusActivity extends BaseActivity
{
    private int result;

    private PayDetail mPayDetail;

    private ViewGroup payAdvertisement;

    private LocalActivityManager manager;

    private TextView payResult, payResultCommodityName,
            payResultCommodityNumber;

    private TitleBar  pay_status_title;

    @Override
    public void preCreate()
    {
        super.preCreate();
        result = getIntent().getIntExtra(EMainActivity.PAY_RESULT, 2);
        mPayDetail = (PayDetail) getIntent().getSerializableExtra(
                EMainActivity.PAY_DETAIL);
    }

    @Override
    protected int setView() {
         return R.layout.activity_pay_status;
    }

    @Override
    protected void findViews() {
        payResult = (TextView) findViewById(R.id.tx_pay_statues);
        payResultCommodityName = (TextView) findViewById(R.id.tx_service_name);
        payResultCommodityNumber = (TextView) findViewById(R.id.tx_book_number);
        pay_status_title= (TitleBar) findViewById(R.id.pay_status_title);
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void init() {


//        setTitleText("购买结果");
//        showBackBar();
        hideTitleBar();
        pay_status_title.setTitle("购买结果");
        pay_status_title.setBackListener(new ViewOnClickListener() {
            @Override
            public void avertRepeatOnClick(View v) {
                setResult();
            }
        });

        if (mPayDetail != null)
        {
            payResultCommodityName.setText(String.format("商品名称:%s", mPayDetail.getName()));
            payResultCommodityNumber.setText(String.format("商品数量:%s", mPayDetail.getNumber()));
        }
        if (result == 0)
        {
            payResult.setText("恭喜你!购买成功");
//            Drawable celebrateSuccess = ResourcesCompat.getDrawable(getResources(), R.mipmap.celebrate_success,null);
//            payResult.setCompoundDrawablesWithIntrinsicBounds(celebrateSuccess, null, null, null);
//            payResultComplete.setText("完成");
        }
        else
        {
            payResult.setText("Sorry!购买失败");
//            Drawable sorryFail = ResourcesCompat.getDrawable(getResources(), R.mipmap.celebrate_success,null);
//            payResultComplete.setText("重新购买");
        }
    }

    @Override
    protected void loadData() {

    }

//    @Override
//    protected View setView()
//    {
//         return R.layout.activity_pay_status;
//        return new PayStatus(this);
//    }
//
//    @Override
//    protected void findViews()
//    {
//        payResult = (ViewGroup) findViewById(PayStatus.payResult);
//        payAdvertisement = (ViewGroup) findViewById(PayStatus.payAdvertisement);
//    }
//
//    @Override
//    protected void initEvent()
//    {
//        setGoBackListener(new GoBackListener()
//        {
//
//            @Override
//            public void goBack()
//            {
//                setResult();
//            }
//        });
//    }
//
//    @Override
//    protected void init()
//    {
//        setTitleBarText("购买结果");
//        manager = getLocalActivityManager();
//    }

    @Override
    public void onBackPressed()
    {
        CWLog.i("debug", "onBackPressed");
        setResult();
    }

//    @Override
//    protected void loadData()
//    {
//        Window payResultWin = manager.startActivity(PayStatus.payResult + "",
//                new Intent(this, PayResultActivity.class));
//        View payResultView = payResultWin.getDecorView();
//        payResult.addView(payResultView);
//        Window payAdvertisementWin = null;
//        try
//        {
//            Intent mIntent = getIntent();
//            payAdvertisementWin = manager.startActivity(
//                    PayStatus.payAdvertisement + "",
//                    new Intent(this, Class.forName(mIntent
//                            .getStringExtra(EMainActivity.ADV_PKG_NAME))));
//            View payAdvertisementView = payAdvertisementWin.getDecorView();
//            payAdvertisement.addView(payAdvertisementView);
//        }
//        catch (Exception e)
//        {
//            e.printStackTrace();
//        }
//    }



    public int getResult()
    {
        return result;
    }

    public PayDetail getPayDetail()
    {
        return mPayDetail;
    }

    public void setResult()
    {
        Intent intent = new Intent();
        intent.putExtra(EMainActivity.PAY_RESULT, result);
        setResult(RESULT_OK, intent);
        finish();
    }

}
